package com.yf.controller.admin.course;

import java.util.List;
import java.util.Map;

import com.yf.entity.course.CourseEntity;
import com.yf.entity.course.CourseTypeEntity;
import com.yf.service.course.CourseService;
import com.yf.vo.CourseBackVo;
import com.yf.vo.OptCourseTypeBackVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import com.yf.response.R;
import com.yf.consts.DaoConst;


/**
 * 课程Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Wed Oct 31 09:51:27 CST 2018
 */
@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private CourseService courseService;

    /**
     * 列表课程
     */
    @RequestMapping("/list")
    @RequiresPermissions("course:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<CourseEntity> courseList = courseService.queryList(params);
        return R.ok(new PageInfo(courseList));
    }

    /**
     * 查看课程
     */
    @SysLog("查看课程")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("course:info")
    public R info(@PathVariable("id") Long id) {
        CourseEntity course = courseService.get(id);

        return R.ok(course);
    }

    /**
     * 保存课程
     */
    @SysLog("保存课程")
    @RequestMapping("/save")
    @RequiresPermissions("course:save")
    public R save(CourseEntity course) {
        courseService.save(course);

        return R.ok(course);
    }

    /**
     * 修改课程
     */
    @SysLog("修改课程")
    @RequestMapping("/update")
    @RequiresPermissions("course:update")
    public R update(CourseEntity course) {
        courseService.update(course);

        return R.ok(course);
    }

    /**
     * 删除课程
     */
    @SysLog("删除课程")
    @RequestMapping("/delete")
    @RequiresPermissions("course:delete")
    public R delete(@RequestBody Long[]ids) {
        courseService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有课程
     */
    @SysLog("所有课程")
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<CourseEntity> courseList = courseService.queryList(params);

        return R.ok(courseList);
    }

    /***********自定义开始***********/

    /**
     * back 课程信息
     * @return
     */
    @RequestMapping("/courseList")
    public R getCourseVoList(@RequestParam Map<String, Object> params){
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<CourseBackVo> list = courseService.courseList(params);
        return R.ok(new PageInfo(list));
    }

    /**
     * 课程选择类型
     * @return
     */
    @RequestMapping("/getCourseTypeList")
    public R getCourseTypeList(){
        List<OptCourseTypeBackVo> list = courseService.courseTypeList();
        return R.ok(list);
    }

}
